package eu.winterwheels.enterprise.service.security;

import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.persistence.EntityManager;

import eu.winterwheels.enterprise.model.User;

// The @Stateless annotation eliminates the need for manual transaction demarcation
@Stateless
public class UserEJB {

   @Inject
   private Logger log;

   @Inject
   private EntityManager em;

   @Inject
   private Event<User> userEventSrc;

   public void register(User user) throws Exception {
      log.info("Registering " + user.getSurname());
      em.persist(user);
      userEventSrc.fire(user);
   }
}
